#!/bin/bash
set -ex
# example: version=115.9.1esr
version=$1
date=$(date +"%Y%m%d")
output=firefox-langpacks-$version-$date.tar.xz
if  [ -z $version ];then
    echo " please input version of firefox!"
    echo " Usage: sh $0  115.9.1esr"
    exit 1
fi
temp_dir=$(mktemp -d)
langpacks_dir="$temp_dir/firefox-langpacks"
mkdir -p "$langpacks_dir"
url=https://archive.mozilla.org/pub/firefox/releases/$version/linux-x86_64/xpi/
wget -r -l1 -A.xpi -nd -P "$langpacks_dir"  $url
tar -cJf $output -C "$temp_dir" firefox-langpacks
rm -r $temp_dir

echo "Downloaded and packed .xpi files into $output"
